package com.lucien.admin.controller.system;

import com.lucien.common.result.GlobalResult;
import com.lucien.system.domain.ChatMessage;
import com.lucien.system.domain.SysGroupMessage;
import com.lucien.system.service.SysGroupMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "群聊信息接口")
@RequestMapping("/groupmsg")
public class SysGroupMessageController {

    @Autowired
    private SysGroupMessageService groupMessageService;

    @PostMapping("/insert")
    @ApiOperation(value = "添加群组聊天记录")
    public GlobalResult insert(@RequestBody SysGroupMessage groupMessage){
        int result = groupMessageService.insert(groupMessage);
        if (result == 1){
            return GlobalResult.success("记录成功", 1);
        }else {
            return GlobalResult.error("记录失败",-1);
        }
    }

    @GetMapping("/{groupId}")
    @ApiOperation(value = "获取群聊信息")
    public GlobalResult groupMsgList(@PathVariable("groupId") Integer groupId){
        List<SysGroupMessage> result = groupMessageService.listGroupMsg(groupId);
        return GlobalResult.success("获取成功", result);
    }

    @GetMapping("/del/{groupId}")
    @ApiOperation(value = "删除群组聊天记录")
    public GlobalResult delMsg(@PathVariable("groupId") Long groupId){
        int result = groupMessageService.delGroupMsg(groupId);
        return GlobalResult.success(result);
    }

    @GetMapping("/groupmsglist/{userId}")
    @ApiOperation(value = "获取用户所在群聊最近一条信息")
    public GlobalResult userGroupMsgList(@PathVariable("userId") Integer userId){
        List<SysGroupMessage> result = groupMessageService.userGroupMsgList(userId);
        return GlobalResult.success("获取成功", result);
    }

    @GetMapping("/frontchatmsg/{groupId}")
    @ApiOperation(value = "获取群聊记录-chatmessage")
    public GlobalResult frontChatMsg(@PathVariable("groupId") Long groupId){
        List<ChatMessage> result = groupMessageService.frontChatMsg(groupId);
        return GlobalResult.success("获取成功", result);
    }
}
